﻿using System;
using System.Data;
using UniMana.Utils.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using UniMana.Utils.Configs;
using System.Windows.Forms;
using DevExpress.Utils;
using UniMana.Data;

namespace UniMana.Win.Personnel
{
    public partial class FrmCheckSubjectClass_LecturerAll : DevExpress.XtraEditors.XtraForm
    {
        private DBMain m_data = new DBMain();
        private DataTable m_tblSchedule;
        private DataTable m_tblPersonnalSubjecClass;
        private DataTable m_tblResult;
        private DataTable m_tblClass;
        int numberlessons = 0;
        int numbersessions = 0;
        int rowFocused = 0;
        string columnFocused = "";

        bool flagEdit = true;
        bool flagAuto = false;
        bool flagAllowEdit;
        int row = -1;
        string colum = "";
        Training_Session_Subject_Class_RoomInfo info;

        // Số cột LeftFix
        int numberColumn = 11;
        // Số dòng cho mỗi lớp học phần
        int rowClass = 6;

        public DevExpress.Utils.WaitDialogForm dlg;

        public FrmCheckSubjectClass_LecturerAll()
        {
            //if (!UniMana.Lib.Sys.Utils.CheckAccessByRule(Utils.Config.RuleConfig.TDDGBH))
            //{
            //    return;
            //}
            InitializeComponent();
        }

        private void FrmCheckSubjectClass_LecturerAll_Load(object sender, EventArgs e)
        {            
            flagAllowEdit = false;
            AutoUpdate.Enabled = true;

            cmbMonth.EditValue = 2;
            cmbYear.EditValue = 2013;

            //cmbMonth.EditValue = Lib.Sys.SysDateTime.Now.Month;
            //cmbYear.EditValue = Lib.Sys.SysDateTime.Now.Year;

            m_tblPersonnalSubjecClass = new DataTable();
            m_tblSchedule = new DataTable();
            m_tblResult = InitalResult(m_tblResult);
            m_tblClass = InitalClass(m_tblClass);
            LoadData();
            rluPersonnel_Personnel.DataSource = m_data.m_DCReadOnly.Personnel_Personnels.GetFullName().ToDataTable();
            rluCatalogue_Degree.GetData(m_data.m_DCReadOnly.Catalogue_Degrees);
            rluTraining_Subject.GetData(m_data.m_DCReadOnly.Training_Subjects);
            rluTraining_Subject_Class.GetData(m_data.m_DCReadOnly.Training_Subject_Classes, "Training_Subject_ClassKey", "ID");
        }

        private void LoadData()
        {
            //try
            {
                dlg = new DevExpress.Utils.WaitDialogForm(MsgConfig.MSG_WAIT, MsgConfig.MSG_LOADING);
                m_tblPersonnalSubjecClass = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.GetPersonnalSubjectClass(m_data.m_DCReadOnly.Training_Subject_Classes,
                    m_data.m_DCReadOnly.Training_Subjects,
                    m_data.m_DCReadOnly.Personnel_Personnels,
                    int.Parse(cmbMonth.EditValue.ToString()),
                    int.Parse(cmbYear.EditValue.ToString())).ToDataTable();
                m_tblSchedule = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.GetAllData(m_data.m_DCReadOnly.Training_Subject_Classes,
                    m_data.m_DCReadOnly.Training_Subjects,
                    m_data.m_DCReadOnly.Personnel_Personnels,
                    m_data.m_DCReadOnly.Catalogue_Degrees,
                    m_data.m_DCReadOnly.Training_Class_Rooms,
                    int.Parse(cmbMonth.EditValue.ToString()),
                    int.Parse(cmbYear.EditValue.ToString())).ToDataTable();
                if ((m_tblSchedule.Rows.Count > 0) && (m_tblPersonnalSubjecClass.Rows.Count > 0))
                {
                    grvView.Columns.Clear();
                    InitalGridView();
                    Analysis();
                    gctView.DataSource = null;
                    gctView.DataSource = m_tblResult;
                    grvView.BestFitColumns();
                    dlg.Close();
                }
                else
                {
                    gctView.DataSource = null;
                    dlg.Close();
                    XtraMessageBox.Show("Không có thông tin dữ liệu trong tháng");
                }
            }
            //catch { dlg.Close(); }
        }

        /// <summary>
        /// Lấy thông tin tên các lớp đầu vào với mã lớp học phần
        /// </summary>
        /// <param name="m_iTrainingSubjectClassKey"></param>
        /// <returns></returns>

        private string ReturnTrainingClass(int m_iTrainingSubjectClassKey)
        {
            DataTable m_tbl = new DataTable();
            m_tbl = m_data.m_DCReadOnly.Training_Student_Subject_Classes.ReturnTrainingClassIDWithTrainingSubjectClassKey(m_data.m_DCReadOnly.Training_Student_Classes,
                m_data.m_DCReadOnly.Training_Classes,
                m_iTrainingSubjectClassKey).ToDataTable();
            string result = "";
            if (m_tbl.Rows.Count > 0)
            {
                for (int i = 0; i < m_tbl.Rows.Count; i++)
                {
                    if (i > 0)
                        //result += Global.Microsoft.VisualBasic.ChrW(10);
                        result += "-";
                    result = result + m_tbl.Rows[i][0].ToString();
                }
            }
            return result;
        }

        /// <summary>
        /// Tính toán số tiết học với các tín chỉ
        /// </summary>
        /// <param name="a"></param>

        private int ReturnNumberLessons(params double[] a)
        {
            int result = 0;
            for (int i = 0; i < a.Length; i++)
            {
                try
                {
                    result = result + int.Parse(a[i].ToString()) * 15;
                }
                catch { continue; }
            }
            return result;
        }

        /// <summary>
        /// Phân tích dữ liệu
        /// </summary>

        private void Analysis()
        {
            // Vị trí dòng để add dữ liệu
            int position = 0;

            m_tblResult = ReInitalResult(m_tblResult);
            for (int i = 0; i < m_tblPersonnalSubjecClass.Rows.Count; i++)
            {
                // add ca 1
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Ca 1");
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Phòng");

                // add ca 2
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Ca 2");
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Phòng");

                // add ca 3
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Ca 3");
                m_tblResult.Rows.Add(m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Catalogue_DegreeKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Training_SubjectKey"],
                    m_tblPersonnalSubjecClass.Rows[i]["Credits1"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits2"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits3"],
                m_tblPersonnalSubjecClass.Rows[i]["Credits4"],
                ReturnNumberLessons(Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits1"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits2"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits3"].ToString()),
                Convert.ToDouble(m_tblPersonnalSubjecClass.Rows[i]["Credits4"].ToString())),
                m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"],
                ReturnTrainingClass(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString())),
                "Phòng");

                // Lọc dữ liệu theo giảng viên và lớp học phần tương ứng
                m_tblClass = ReInitalClass(m_tblClass);
                for (int j = 0; j < m_tblSchedule.Rows.Count; j++)
                {
                    if ((m_tblSchedule.Rows[j]["Personnel_PersonnelKey"].ToString() == m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"].ToString()) && (m_tblSchedule.Rows[j]["Training_Subject_ClassKey"].ToString() == m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString()))
                    {
                        m_tblClass.Rows.Add(m_tblSchedule.Rows[j]["Personnel_PersonnelKey"],
                            m_tblSchedule.Rows[j]["Catalogue_DegreeKey"],
                            m_tblSchedule.Rows[j]["Training_SubjectKey"],
                            m_tblSchedule.Rows[j]["SubjectID"],
                            m_tblSchedule.Rows[j]["SubjectName"],
                            m_tblSchedule.Rows[j]["Credits1"],
                            m_tblSchedule.Rows[j]["Credits2"],
                            m_tblSchedule.Rows[j]["Credits3"],
                            m_tblSchedule.Rows[j]["Credits4"],
                            m_tblSchedule.Rows[j]["Training_Subject_ClassKey"],
                            m_tblSchedule.Rows[j]["ClassID"],
                            m_tblSchedule.Rows[j]["ClassName"],
                            m_tblSchedule.Rows[j]["Training_Class_RoomKey"],
                            m_tblSchedule.Rows[j]["RegistTime"],
                            m_tblSchedule.Rows[j]["Training_WeekDayKey"],
                            m_tblSchedule.Rows[j]["Training_SessionKey"],
                            m_tblSchedule.Rows[j]["Lessons"],
                            m_tblSchedule.Rows[j]["Status"],
                            m_tblSchedule.Rows[j]["Note"],
                            m_tblSchedule.Rows[j]["RoomID"]);
                        m_tblSchedule.Rows.RemoveAt(j);
                        j--;
                    }
                }
                // Đánh dấu các buổi giảng trong tuần
                for (int j = 0; j < m_tblClass.Rows.Count; j++)
                {
                    DateTime daycurrent = Convert.ToDateTime(m_tblClass.Rows[j]["RegistTime"]);
                    DateTime daytime = new DateTime(daycurrent.Year, daycurrent.Month, daycurrent.Day);
                    string caption = ClsReturnDayOfWeek.convertToString(daytime) + "-" + daycurrent.Day + "/" + daycurrent.Month + "/" + daycurrent.Year;

                    if (m_tblClass.Rows[j]["Training_SessionKey"].ToString() == "1")
                    {
                        // Thêm thời điểm buổi học
                        if (m_tblClass.Rows[j]["Lessons"].ToString() != "")
                        {
                            m_tblResult.Rows[position][caption] = m_tblClass.Rows[j]["Lessons"];
                        }
                        else
                            m_tblResult.Rows[position][caption] = "x";
                        // Thêm phòng học cho buổi
                        m_tblResult.Rows[position + 1][caption] = m_tblClass.Rows[j]["RoomID"];
                        continue;
                    }
                    if (m_tblClass.Rows[j]["Training_SessionKey"].ToString() == "2")
                    {
                        // Thêm thời điểm buổi học
                        if (m_tblClass.Rows[j]["Lessons"].ToString() != "")
                        {
                            m_tblResult.Rows[position + 2][caption] = m_tblClass.Rows[j]["Lessons"];
                        }
                        else
                            m_tblResult.Rows[position + 2][caption] = "x";
                        // Thêm phòng học cho buổi
                        m_tblResult.Rows[position + 3][caption] = m_tblClass.Rows[j]["RoomID"];
                        continue;
                    }
                    if (m_tblClass.Rows[j]["Training_SessionKey"].ToString() == "3")
                    {
                        // Thêm thời điểm buổi học
                        if (m_tblClass.Rows[j]["Lessons"].ToString() != "")
                        {
                            m_tblResult.Rows[position + 4][caption] = m_tblClass.Rows[j]["Lessons"];
                        }
                        else
                            m_tblResult.Rows[position + 4][caption] = "x";
                        // Thêm phòng học cho buổi
                        m_tblResult.Rows[position + 5][caption] = m_tblClass.Rows[j]["RoomID"];
                        continue;
                    }
                }
                // Ghi tổng số tiết
                for (int j = 0; j < rowClass; j++)
                {
                    m_tblResult.Rows[position + j]["SumLesson"] = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.ReturnNumberLessons(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString()),
                        m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"].ToString()).ToString();
                    m_tblResult.Rows[position + j]["SumSession"] = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.ReturnNumberSessions(int.Parse(m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString()),
                        m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"].ToString()).ToString();
                }
                // Tiếp tục sang lớp kế tiếp
                position += rowClass;
            }
        }

        /// <summary>
        /// Khởi tạo gridview
        /// </summary>

        private void InitalGridView()
        {
            // gridband1
            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl0;
            gcl0 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl0 });
            gcl0.Caption = "Họ tên giảng viên";
            gcl0.Name = "Personnel_PersonnelKey";
            gcl0.FieldName = "Personnel_PersonnelKey";
            gcl0.Visible = true;
            gcl0.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl0.ColumnEdit = rluPersonnel_Personnel;
            gcl0.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl0);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl1;
            gcl1 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl1 });
            gcl1.Caption = "HH / HV";
            gcl1.Name = "Catalogue_DegreeKey";
            gcl1.FieldName = "Catalogue_DegreeKey";
            gcl1.Visible = true;
            //gcl1.Visible = false;
            gcl1.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl1.ColumnEdit = rluCatalogue_Degree;
            gcl1.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl1);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl2;
            gcl2 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl2 });
            gcl2.Caption = "Môn học";
            gcl2.Name = "Training_SubjectKey";
            gcl2.FieldName = "Training_SubjectKey";
            gcl2.Visible = true;
            gcl2.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl2.ColumnEdit = rluTraining_Subject;
            gcl2.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl2);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl3;
            gcl3 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl3 });
            gcl3.Caption = "LT";
            gcl3.Name = "Credits1";
            gcl3.FieldName = "Credits1";
            gcl3.Visible = true;
            gcl3.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl3.OptionsColumn.AllowEdit = false;
            gcl3.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl3);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl4;
            gcl4 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl4 });
            gcl4.Caption = "BT";
            gcl4.Name = "Credits2";
            gcl4.FieldName = "Credits2";
            gcl4.Visible = true;
            gcl4.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl4.OptionsColumn.AllowEdit = false;
            gcl4.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl4);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl5;
            gcl5 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl5 });
            gcl5.Caption = "TH";
            gcl5.Name = "Credits3";
            gcl5.FieldName = "Credits3";
            gcl5.Visible = true;
            gcl5.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl5.OptionsColumn.AllowEdit = false;
            gcl5.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl5);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl6;
            gcl6 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl6 });
            gcl6.Caption = "ĐA";
            gcl6.Name = "Credits4";
            gcl6.FieldName = "Credits4";
            gcl6.Visible = true;
            gcl6.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl6.OptionsColumn.AllowEdit = false;
            gcl6.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl6);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl61;
            gcl61 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl61 });
            gcl61.Caption = "Số tiết";
            gcl61.Name = "LessonsAll";
            gcl61.FieldName = "LessonsAll";
            gcl61.Visible = true;
            gcl61.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl61.OptionsColumn.AllowEdit = false;
            //gcl61.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl61);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl7;
            gcl7 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl7 });
            gcl7.Caption = "Mã lớp";
            gcl7.Name = "Training_Subject_ClassKey";
            gcl7.FieldName = "Training_Subject_ClassKey";
            gcl7.Visible = true;
            gcl7.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl7.OptionsColumn.AllowEdit = false;
            gcl7.ColumnEdit = rluTraining_Subject_Class;
            gcl7.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl7);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl71;
            gcl71 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl71 });
            gcl71.Caption = "Lớp";
            gcl71.Name = "Training_Class";
            gcl71.FieldName = "Training_Class";            
            gcl71.Visible = true;
            gcl71.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl71.OptionsColumn.AllowEdit = false;

            //gcl71.AppearanceCell.Options.UseTextOptions = true;
            //gcl71.AppearanceCell.TextOptions.Trimming = DevExpress.Utils.Trimming.None;
            //gcl71.AppearanceCell.TextOptions.WordWrap = DevExpress.Utils.WordWrap.NoWrap;

            grb1.Columns.Add(gcl71);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl8;
            gcl8 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl8 });
            gcl8.Caption = "Ca\nPhòng";
            gcl8.Name = "Training_SessionKey";
            gcl8.FieldName = "Training_SessionKey";
            gcl8.Visible = true;
            gcl8.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
            gcl8.OptionsColumn.AllowEdit = false;
            //gcl8.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb1.Columns.Add(gcl8);

            // gridband2
            for (int i = 0; i < DateTime.DaysInMonth(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString())); i++)
            {
                DateTime daytime = new DateTime(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString()), i + 1);
                string gclCaption = (i + 1).ToString() + "\n" + ClsReturnDayOfWeek.convertToString(daytime);// + "/" + cmbMonth.EditValue.ToString() + "/" + cmbYear.EditValue.ToString();
                string gclName = ClsReturnDayOfWeek.convertToString(daytime) + "-" + (i + 1).ToString() + "/" + cmbMonth.EditValue.ToString() + "/" + cmbYear.EditValue.ToString();
                DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl9;
                gcl9 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
                grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl9 });
                gcl9.Caption = gclCaption;
                gcl9.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
                gcl9.Name = gclName;
                gcl9.FieldName = gclName;
                gcl9.Visible = true;
                gcl9.ColumnEdit = rluLessons;
                gcl9.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                gcl9.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
                grb2.Columns.Add(gcl9);
            }

            // gridband3
            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl10;
            gcl10 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl10 });
            gcl10.Caption = "Tổng\nbuổi";
            gcl10.Name = "SumSession";
            gcl10.FieldName = "SumSession";
            gcl10.Visible = true;
            gcl10.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl10.OptionsColumn.AllowEdit = false;
            gcl10.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb3.Columns.Add(gcl10);

            DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gcl11;
            gcl11 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            grvView.Columns.AddRange(new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn[] { gcl11 });
            gcl11.Caption = "Tổng\ntiết";
            gcl11.Name = "SumLesson";
            gcl11.FieldName = "SumLesson";
            gcl11.Visible = true;
            gcl11.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
            gcl11.OptionsColumn.AllowEdit = false;
            gcl11.AppearanceCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            grb3.Columns.Add(gcl11);
        }

        /// <summary>
        /// Khởi tạo Datatable kết quả
        /// </summary>
        /// <param name="m_tblTableInital"></param>
        /// <returns></returns>

        private DataTable InitalResult(DataTable m_tblTableInital)
        {
            m_tblTableInital = new DataTable();
            m_tblTableInital.Columns.Add("Personnel_PersonnelKey", typeof(Guid));
            m_tblTableInital.Columns.Add("Catalogue_DegreeKey");
            m_tblTableInital.Columns.Add("Training_SubjectKey");
            m_tblTableInital.Columns.Add("Credits1");
            m_tblTableInital.Columns.Add("Credits2");
            m_tblTableInital.Columns.Add("Credits3");
            m_tblTableInital.Columns.Add("Credits4");
            m_tblTableInital.Columns.Add("LessonsAll");
            m_tblTableInital.Columns.Add("Training_Subject_ClassKey");
            m_tblTableInital.Columns.Add("Training_Class");
            m_tblTableInital.Columns.Add("Training_SessionKey");
            for (int i = 0; i < DateTime.DaysInMonth(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString())); i++)
            {
                DateTime daytime = new DateTime(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString()), i + 1);
                string Caption = ClsReturnDayOfWeek.convertToString(daytime) + "-" + (i + 1).ToString() + "/" + cmbMonth.EditValue.ToString() + "/" + cmbYear.EditValue.ToString();
                m_tblTableInital.Columns.Add(Caption);
            }
            m_tblTableInital.Columns.Add("SumSession");
            m_tblTableInital.Columns.Add("SumLesson");
            return m_tblTableInital;
        }

        private DataTable ReInitalResult(DataTable m_tblTableInital)
        {
            m_tblTableInital.Columns.Clear();
            m_tblTableInital.Rows.Clear();
            m_tblTableInital.Clear();
            m_tblTableInital = new DataTable();
            m_tblTableInital = InitalResult(m_tblTableInital);
            return m_tblTableInital;
        }

        /// <summary>
        /// Khởi tạo Datatable chứa thông tin chi tiết lớp học phần của giảng viên
        /// </summary>
        /// <param name="m_tblTableInital"></param>
        /// <returns></returns>

        private DataTable InitalClass(DataTable m_tblTableInital)
        {
            m_tblTableInital = new DataTable();
            m_tblTableInital.Columns.Add("Personnel_PersonnelKey");
            m_tblTableInital.Columns.Add("Catalogue_DegreeKey");
            m_tblTableInital.Columns.Add("Training_SubjectKey");
            m_tblTableInital.Columns.Add("SubjectID");
            m_tblTableInital.Columns.Add("SubjectName");
            m_tblTableInital.Columns.Add("Credits1");
            m_tblTableInital.Columns.Add("Credits2");
            m_tblTableInital.Columns.Add("Credits3");
            m_tblTableInital.Columns.Add("Credits4");
            m_tblTableInital.Columns.Add("Training_Subject_ClassKey");
            m_tblTableInital.Columns.Add("ClassID");
            m_tblTableInital.Columns.Add("ClassName");
            m_tblTableInital.Columns.Add("Training_Class_RoomKey");
            m_tblTableInital.Columns.Add("RegistTime");
            m_tblTableInital.Columns.Add("Training_WeekDayKey");
            m_tblTableInital.Columns.Add("Training_SessionKey");
            m_tblTableInital.Columns.Add("Lessons");
            m_tblTableInital.Columns.Add("Status");
            m_tblTableInital.Columns.Add("Note");
            m_tblTableInital.Columns.Add("RoomID");
            return m_tblTableInital;
        }

        private DataTable ReInitalClass(DataTable m_tblTableInital)
        {
            m_tblTableInital.Columns.Clear();
            m_tblTableInital.Rows.Clear();
            m_tblTableInital.Clear();
            m_tblTableInital = InitalClass(m_tblTableInital);
            return m_tblTableInital;
        }

        /// <summary>
        /// Thay đổi tháng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void cmbMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadData();
        }

        /// <summary>
        /// Thay đổi năm
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void cmbYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadData();
        }

        /// <summary>
        /// Tô màu gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        int _flag = 0;
        private void grvView_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            try
            {
                GridView View = sender as GridView;
                // Đánh dấu cột chủ nhật
                if (e.Column.Caption.Contains("CN"))
                {
                    e.Appearance.BackColor = Color.AliceBlue;
                }
                // Đánh dấu các buổi giảng dự kiến
                if (!View.IsFilterRow(e.RowHandle))
                {
                    if (e.CellValue.ToString() == "x")
                    {
                        e.Appearance.BackColor = Color.Tan;
                    }
                }

                // Đánh dấu buổi giảng có ghi chú

                //if ((_flag == 0) || (ClsPublic._flagLoadMarkNote))
                //{
                //    DataTable m_tblMarkNote = new DataTable();
                //    m_tblMarkNote = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.GetDataMarkNote().ToDataTable();
                //    if (m_tblMarkNote.Rows.Count > 0)
                //    {
                //        for (int i = 0; i < m_tblMarkNote.Rows.Count; i++)
                //        {
                //            for (int j = numberColumn; j < numberColumn + DateTime.DaysInMonth(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString())); j++)
                //            {
                //                //if (char.IsNumber(grvView.Columns[j].Caption.ToString(), 0))
                //                //{
                //                    try
                //                    {
                //                        string name = grvView.Columns[j].Name.ToString();
                //                        name = name.Replace('/', '-');
                //                        string[] array = name.Split('-');
                //                        DateTime dat = Convert.ToDateTime(m_tblMarkNote.Rows[i]["RegistTime"].ToString());
                //                        if (array[1].ToString() == dat.Day.ToString())// dieu kien danh dau
                //                        {
                //                            e.Appearance.BackColor = Color.Red;
                //                        }
                //                    }
                //                    catch { continue; }
                //                //}
                //            }
                //        }
                //    }
                //    _flag = 1;
                //    ClsPublic._flagLoadMarkNote = false;
                //}
            }
            catch { }
        }

        /// <summary>
        /// Trả về giá trị của Buổi học
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>

        private int ConvertTraining_Session(string session)
        {
            if (session == "Ca 1")
                return 1;
            if (session == "Ca 2")
                return 2;
            if (session == "Ca 3")
                return 3;
            return 0;
        }

        /// <summary>
        /// Chuyển sang kiểu ngày tháng
        /// </summary>
        /// <param name="m_strdatetime"></param>
        /// <returns></returns>

        private DateTime ConvertDatetime(string m_strdatetime)
        {
            DateTime datetime;
            m_strdatetime = m_strdatetime.Replace('-', '/');
            string[] a = m_strdatetime.Split('/');
            datetime = new DateTime(int.Parse(a[3].ToString()), int.Parse(a[2].ToString()), int.Parse(a[1].ToString()));
            return datetime;
        }

        /// <summary>
        /// Lưu dữ liệu đánh giá buổi giảng
        /// </summary>

        private void grvView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (flagEdit)
            {
                rowFocused = int.Parse(grvView.GetFocusedRowCellValue("Training_Subject_ClassKey").ToString());
                columnFocused = grvView.GetFocusedRowCellValue("Personnel_PersonnelKey").ToString();
                // Kiểm tra không điền thông tin
                if (grvView.GetFocusedRowCellValue(grvView.FocusedColumn).ToString() == "")
                {
                    // Đánh dấu là chưa xác định khi không đánh giá
                    colum = grvView.FocusedColumn.Name;
                    row = grvView.FocusedRowHandle;
                    // Lưu thông tin là buổi giảng chưa xác định
                    info = new Training_Session_Subject_Class_RoomInfo(ConvertTraining_Session(m_tblResult.Rows[grvView.FocusedRowHandle]["Training_SessionKey"].ToString()),
                        int.Parse(grvView.GetFocusedRowCellValue("Training_Subject_ClassKey").ToString()),
                        ConvertDatetime(grvView.FocusedColumn.Name));
                    if (info.Properties.Training_SessionKey > 0)
                    {
                        info.Properties.Lessons = null;
                        info.Save();
                    }
                }
                else
                {
                    string colum1 = grvView.FocusedColumn.Name;
                    int row1 = grvView.FocusedRowHandle;
                    if (grvView.GetFocusedRowCellValue(grvView.FocusedColumn).ToString() == "x")
                    {
                        // Lưu thông tin là buổi giảng chưa xác định
                        int asdf = ConvertTraining_Session(m_tblResult.Rows[grvView.FocusedRowHandle]["Training_SessionKey"].ToString());
                        int fdasf = int.Parse(grvView.GetFocusedRowCellValue("Training_Subject_ClassKey").ToString());
                        info = new Training_Session_Subject_Class_RoomInfo(ConvertTraining_Session(m_tblResult.Rows[grvView.FocusedRowHandle]["Training_SessionKey"].ToString()),
                            int.Parse(grvView.GetFocusedRowCellValue("Training_Subject_ClassKey").ToString()),
                            ConvertDatetime(grvView.FocusedColumn.Name));
                        if (info.Properties.Training_SessionKey > 0)
                        {
                            info.Properties.Lessons = null;
                            info.Save();
                        }
                    }
                    else
                    {
                        // Lưu thông tin là buổi giảng đã xác định
                        info = new Training_Session_Subject_Class_RoomInfo(ConvertTraining_Session(m_tblResult.Rows[grvView.FocusedRowHandle]["Training_SessionKey"].ToString()),
                            int.Parse(grvView.GetFocusedRowCellValue("Training_Subject_ClassKey").ToString()),
                            ConvertDatetime(grvView.FocusedColumn.Name));
                        if (info.Properties.Training_SessionKey > 0)
                        {
                            string values = grvView.GetRowCellValue(row1, colum1).ToString();
                            info.Properties.Lessons = int.Parse(values);
                            info.Save();
                        }
                    }
                }
                flagEdit = false;
                flagAuto = true;
            }
        }

        /// <summary>
        /// Lập lại giá trị tổng các buổi giảng, tiết học
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void AutoUpdate_Tick(object sender, EventArgs e)
        {
            if (flagAuto)
            {
                flagAuto = false;
                numberlessons = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.ReturnNumberLessons(rowFocused,
                        columnFocused);
                numbersessions = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.ReturnNumberSessions(rowFocused,
                        columnFocused);
                // *6 : 1 lớp học phần 6 dòng
                for (int i = 0; i < rowClass; i++)
                {
                    grvView.SetRowCellValue((ReturnPositionClassPerson(rowFocused, columnFocused) * rowClass) + i, "SumLesson", numberlessons);
                    grvView.SetRowCellValue((ReturnPositionClassPerson(rowFocused, columnFocused) * rowClass) + i, "SumSession", numbersessions);
                }
            }
            if (flagEdit == false)
                flagEdit = true;
        }

        /// <summary>
        /// Trả về vị trí của ô vừa thay đổi giá trị
        /// </summary>
        /// <param name="ClassKey"></param>
        /// <param name="Personnal"></param>
        /// <returns></returns>

        private int ReturnPositionClassPerson(int ClassKey, string Personnal)
        {
            for (int i = 0; i < m_tblPersonnalSubjecClass.Rows.Count; i++)
            {
                if ((m_tblPersonnalSubjecClass.Rows[i]["Training_Subject_ClassKey"].ToString() == ClassKey.ToString()) && (m_tblPersonnalSubjecClass.Rows[i]["Personnel_PersonnelKey"].ToString() == Personnal))
                    return i;
            }
            return 0;
        }

        /// <summary>
        /// Cài đặt chỉ cho chỉnh sửa các buổi dự kiến
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void grvView_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            for (int i = 0; i < DateTime.DaysInMonth(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString())); i++)
            {
                DateTime daytime = new DateTime(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString()), i + 1);
                string columnname = ClsReturnDayOfWeek.convertToString(daytime) + "-" + (i + 1).ToString() + "/" + cmbMonth.EditValue.ToString() + "/" + cmbYear.EditValue.ToString();
                if (this.grvView.FocusedColumn.Name == columnname)
                {
                    if (grvView.GetFocusedRowCellValue(grvView.FocusedColumn).ToString() != "")
                    {
                        if (grvView.GetFocusedRowCellValue(grvView.FocusedColumn).ToString().Length > 1)
                        {
                            flagAllowEdit = false;
                            e.Cancel = true;
                        }
                        else
                        {
                            flagAllowEdit = true;
                            e.Cancel = false;
                        }
                    }
                    else
                    {
                        flagAllowEdit = false;
                        e.Cancel = true;
                    }
                }
            }
            if (row > -1)
            {
                grvView.SetRowCellValue(row, colum, "x");
                colum = "";
                row = -1;
            }
        }

        /// <summary>
        /// Hiển thị comment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void họcBùToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int r = grvView.FocusedRowHandle;
            int c = grvView.FocusedColumn.ColumnHandle;
            if ((r >= 0) && (c >= 0))
            {
                string m_strPersonnalKey = "";
                int m_iClassKey = 0;
                string m_strDegree = "";
                string m_strSubject = "";
                DateTime m_dDay = new DateTime();
                int m_iSession = 0;

                m_strPersonnalKey = grvView.GetRowCellValue(grvView.FocusedRowHandle, "Personnel_PersonnelKey").ToString();
                m_iClassKey = int.Parse(grvView.GetRowCellValue(grvView.FocusedRowHandle, "Training_Subject_ClassKey").ToString());
                m_strDegree = grvView.GetRowCellDisplayText(grvView.FocusedRowHandle, "Catalogue_DegreeKey").ToString();
                m_strSubject = grvView.GetRowCellDisplayText(grvView.FocusedRowHandle, "Training_SubjectKey").ToString();
                if (grvView.GetRowCellDisplayText(grvView.FocusedRowHandle, "Training_SessionKey").ToString().Length < 5)
                    m_iSession = ConvertTraining_Session(grvView.GetRowCellDisplayText(grvView.FocusedRowHandle, "Training_SessionKey").ToString());
                else
                    m_iSession = 0;
                if ((c >= numberColumn) && (c < numberColumn + DateTime.DaysInMonth(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString()))))
                {
                    string caption = grvView.FocusedColumn.Caption;
                    caption = caption.Replace('\n', '|');
                    string[] array = caption.Split('|');
                    m_dDay = new DateTime(int.Parse(cmbYear.EditValue.ToString()), int.Parse(cmbMonth.EditValue.ToString()), int.Parse(array[0].ToString()));
                }
                FrmCheckSubjectClass_LecturerAll_AddSession adds = new FrmCheckSubjectClass_LecturerAll_AddSession(m_strPersonnalKey, m_iClassKey, m_strDegree, m_strSubject, m_dDay, m_iSession);
                adds.ShowDialog();

                if (ClsPublic._flagLoadSession)
                {
                    // Làm mới lại dữ liệu
                    LoadData();
                    ClsPublic._flagLoadSession = false;
                }
            }
            //string colum1 = grvView.FocusedColumn.Name;
        }

        /// <summary>
        /// Comment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        Training_Session_Subject_Class_RoomInfo tsessioninfo;
        private void ttcView_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            try
            {
                if ((char.IsNumber(grvView.FocusedColumn.Caption.PadLeft(1), 0) == true) && (flagAllowEdit))
                {
                    tsessioninfo = new Training_Session_Subject_Class_RoomInfo(grvView.GetRowCellValue(grvView.FocusedRowHandle, "Personnel_PersonnelKey").ToString(),
                        int.Parse(grvView.GetRowCellValue(grvView.FocusedRowHandle, "Training_Subject_ClassKey").ToString()),
                        ConvertDatetime(grvView.FocusedColumn.Name),
                        ConvertTraining_Session(grvView.GetRowCellDisplayText(grvView.FocusedRowHandle, "Training_SessionKey").ToString()));
                    if (tsessioninfo.Properties.Training_SessionKey > 0)
                    {
                        if (tsessioninfo.Properties.Note != "")
                        {
                            e.Info = new ToolTipControlInfo(e.SelectedControl.Focused, "Info", "Content");
                            SuperToolTip SuperTip = new SuperToolTip();
                            SuperToolTipSetupArgs args = new SuperToolTipSetupArgs();
                            args.Title.Text = "Ghi chú:";
                            args.Contents.Text = tsessioninfo.Properties.Note;
                            SuperTip.Setup(args);
                            (e.Info as ToolTipControlInfo).SuperTip = SuperTip;
                        }
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Chỉnh sửa Ghi chú
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if ((char.IsNumber(grvView.FocusedColumn.Caption.PadLeft(1), 0) == true) && (flagAllowEdit))
            {
                FrmCheckSubjectClass_LecturerAll_EditComment editcomment = new FrmCheckSubjectClass_LecturerAll_EditComment(tsessioninfo);
                editcomment.ShowDialog();
                flagAllowEdit = false;
                ClsPublic._flagLoadMarkNote = false;
            }
        }

        //public class MyXPaint : XPaint
        //{
        //    public override void DrawFocusRectangle(Graphics g, Rectangle r, Color foreColor, Color backColor)
        //    {
        //        if (!CanDraw(r)) return;
        //        Brush hb = Brushes.Black;
        //        g.FillRectangle(hb, new Rectangle(r.X, r.Y, 2, r.Height - 2)); // left
        //        g.FillRectangle(hb, new Rectangle(r.X, r.Y, r.Width - 2, 2));  // top
        //        g.FillRectangle(hb, new Rectangle(r.Right - 2, r.Y, 2, r.Height - 2)); // right
        //        g.FillRectangle(hb, new Rectangle(r.X, r.Bottom - 2, r.Width, 2)); // bottom
        //    }
        //}

        //private void SetMyGraphics()
        //{
        //    FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic);
        //    fi.SetValue(null, new MyXPaint());
        //}

        //int _flag = 0;
        private void grvView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            GridView currentView = sender as GridView;
            Rectangle r = e.Bounds;
            if ((e.RowHandle != 0) & (e.RowHandle % 6 == 0) && (char.IsNumber(e.Column.Caption.PadLeft(1), 0)))
            {
                //e.Graphics.DrawLine(Pens.Blue, r.X, r.Y, r.Left, r.Bottom);//left
                //e.Graphics.DrawLine(Pens.Blue, r.Left, r.Bottom, r.Right, r.Bottom);//bottom
                //e.Graphics.DrawLine(Pens.Blue, r.Right, r.Bottom, r.Right, r.Top);//right
                e.Graphics.DrawLine(Pens.Blue, r.Right, r.Top, r.X, r.Y);//top
                e.Appearance.DrawString(e.Cache, e.DisplayText, r);
                //e.Handled = true;
            }

            // Đánh dấu các buổi có ghi chú
            //if ((_flag == 0) || (ClsPublic._flagLoadMarkNote))
            //{
            //    DataTable m_tblMarkNote = new DataTable();
            //    m_tblMarkNote = m_data.m_DCReadOnly.Training_Session_Subject_Class_Rooms.GetDataMarkNote().ToDataTable();
            //    if (m_tblMarkNote.Rows.Count > 0)
            //    {
            //        for (int i = 0; i < m_tblMarkNote.Rows.Count; i++)
            //        {
            //            if (char.IsNumber(e.Column.Caption.ToString(), 0))
            //            {
            //                string name = e.Column.Name.ToString();
            //                name = name.Replace('\\', '-');
            //                string[] array = name.Split('-');
            //                DateTime dat = Convert.ToDateTime(m_tblMarkNote.Rows[i]["RegistTime"].ToString());
            //                if (array[1].ToString() == dat.Day.ToString())// dieu kien danh dau
            //                {
            //                    //e.Graphics.DrawLine(Pens.Red, r.X, r.Y, r.Left, r.Bottom);//left
            //                    //e.Graphics.DrawLine(Pens.Blue, r.Left, r.Bottom, r.Right, r.Bottom);//bottom
            //                    e.Graphics.DrawLine(Pens.Red, r.Right, r.Bottom, r.Right, r.Top);//right
            //                    e.Graphics.DrawLine(Pens.Red, r.Right, r.Top, r.X, r.Y);//top
            //                    e.Appearance.DrawString(e.Cache, e.DisplayText, r);
            //                }
            //            }
            //        }
            //    }
            //    _flag = 1;
            //    ClsPublic._flagLoadMarkNote = false;
            //}
        }
    }
}